'use strict';

angular.module('Query')
    .directive("myScroll", function($window) {
        return function(scope, element, attrs) {
            var scrollEl = angular.element('div[class=query-context]');
            scrollEl.scroll(onScroll);

            scope.$on('$destroy', function() {
                scrollEl.off('scroll', onScroll);
            });

            function onScroll() {
                for (var i = 0; i < scope.data.bizCatalog.length + 2; i++) {
                    var show_top = angular.element('.list-exp_' + i).offset().top,
                        hide_top = 139 + i * 35;
                    if (show_top <= hide_top) {
                        angular.element('.list-icon-fix_' + i).removeClass('list-icon-hide');
                        angular.element('.list-icon_' + i).addClass('list-icon-show list-icon-hide-cursor');

                        for (var j = 0; j < i; j++) {
                            angular.element('.list-icon_' + j).removeClass('list-icon-show');
                        }
                        angular.element('.exp_' + i).addClass('list-icon-hide');
                    } else {
                        angular.element('.exp_' + i).removeClass('list-icon-hide');
                        angular.element('.list-icon_' + i).removeClass('list-icon-show list-icon-hide-cursor');
                        angular.element('.list-icon-fix_' + i).addClass('list-icon-hide');
                    }
                }
            }

        };
    });
